package com.coldchain.auth.module.client.api;

import com.coldchain.auth.feign.IUserService;
import com.coldchain.common.msg.ObjectRestResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * @ClassName MainController
 * @Description TODO
 * @Author fangliai
 * @Date 2018/9/1 16:11
 * @Vesion 1
**/
@Controller
@ApiIgnore
public class UserController {
    @Autowired
    private IUserService userService;
    @RequestMapping("/login")
    public ModelAndView login(String scope , String redirect_url){
        ModelAndView view=new ModelAndView("login");
        view.addObject("scope",scope);
        view.addObject("redirect_url",redirect_url);
        return view;
    }

    /**
     * 获取用户祥情
     * @param userId 为空则获取当前登录人
     * @return
     */
    @RequestMapping("/user/info")
    @ResponseBody
    public ObjectRestResponse<Map<String,Object>> getUserInof(String userId){
        if(StringUtils.isEmpty(userId)){
            return  userService.getUserInfoByUserId(userId);
        }else {
            return  userService.getCurrentUserInfo();
        }
    }


    /**
     * 修改用户密码
     * @return
     */
    @PostMapping("/user/modifyPassword")
    @ResponseBody
    public ObjectRestResponse<Map<String,Object>> modifyPassword(String oldpwd,String newspwd){
        return userService.modifyPassword(oldpwd,newspwd);
    }
}
